package com.cogwheel.framework.util;

import java.io.File;
import java.io.IOException;
import java.nio.IntBuffer;
import java.util.HashMap;

import javax.media.opengl.GL;

import com.cogwheel.framework.init.CPreferences;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureIO;

public class CAssets {
	private static final String TAG = "CWGAssets";
	public static long Size = 0L;
	private static HashMap<String, Texture> assets = new HashMap<String, Texture>();
	public static IntBuffer textures;
	
	public static boolean iLoaded = false;
	
	public static void LoadGraphics(GL gl)
	{
		iLoaded = true;
	}
	
	public static Texture CWGGetTexture(String name){ return assets.get(name); }
	public static void CWGLoadTexture(CPreferences preferences, String name, String filePlace, GL gl){
		try{
			Texture tmp = TextureIO.newTexture(new File(preferences.FOLDER_ASSETS + filePlace), true);
			
			tmp.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
			tmp.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
			
			assets.put(name, tmp);
			
			Size += tmp.getEstimatedMemorySize();
			CDebug.info(TAG, "Successfully loaded " + filePlace + " [" + tmp.getWidth() + "x" + tmp.getHeight() + "]");
		}catch (IOException e){
			CDebug.error(TAG, "Loading " + name + " (" + filePlace + ") failed! Reason: " + e.getMessage());
		}
	}
}
